home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).adf / HP-10C / calc.mod < prev    next >
Text File  |  1988-02-24  |  4KB  |  150 lines

  1. MODULE Calculator;
  2.  
  3. (* This module is an attempt at using Intuition from Modula-2.
  4.  
  5.    Note: "Wait" function must be imported frlom Fixes, instead of
  6.    Tasks. The one in Tasks does not work.
  7.  
  8.    Created: Duncan Prindle,  September 1, 1986
  9.  
  10.    Modified: Perhaps
  11.  
  12. *)
  13.  
  14. FROM CalcDisplay   IMPORT DisplayX;
  15. FROM CalcFunctions IMPORT EXTENDX, ErrorType, X, SAME, DECI, NDeci;
  16. FROM CalcGadgets   IMPORT InitBorder, InitGadgets, InitWindow,
  17.                           ErrorFunction, CalcButtonPtr, CalcButton;
  18. FROM CalcMenus     IMPORT MenuHandle, InitMenus;
  19.  
  20. FROM InOut        IMPORT WriteLn, WriteString;
  21. FROM Intuition    IMPORT
  22.                          IntuitionName, IntuitionBase, 
  23.                          IDCMPFlags, IDCMPFlagSet,
  24.                          GadgetPtr, Gadget, GadgetFlags, GadgetFlagSet,
  25.                          ActivationFlags, ActivationFlagSet,
  26.                          BorderPtr, Border, DrawBorder, Requester,
  27.                          IntuitionTextPtr, IntuitionText, PrintIText,
  28.                          IntuiMessagePtr, IntuiMessage,
  29.                          WindowPtr, MenuPtr;
  30. FROM Libraries    IMPORT OpenLibrary, CloseLibrary;
  31. FROM MathLib0     IMPORT log, power;
  32. FROM Menus        IMPORT SetMenuStrip, ClearMenuStrip;
  33. FROM Ports        IMPORT GetMsg;
  34. FROM Tasks        IMPORT SignalSet, Wait;
  35. FROM Storage      IMPORT ALLOCATE, CreateHeap, DEALLOCATE, DestroyHeap;
  36. FROM SYSTEM       IMPORT ADR, BYTE, ADDRESS, LONGWORD, NULL;
  37. FROM Windows      IMPORT CloseWindow;
  38.  
  39.  
  40.  
  41. CONST
  42.   IntuitionRev = 29;
  43.  
  44. VAR
  45.   HEAP      : BOOLEAN;
  46.   bPtr      : ARRAY[0..3] OF BorderPtr;
  47.   gPtr      : ARRAY[0..46] OF GadgetPtr;
  48.   Button    : GadgetPtr;
  49.   Signal    : IntuiMessagePtr;
  50.   Sig1      : SignalSet;
  51.   CGadget   : CARDINAL;
  52.   Display   : ARRAY[0..14] OF CHAR;
  53.   DISPLAY   : IntuitionText;
  54.   wp        : WindowPtr;
  55.   KEY       : CalcButtonPtr;
  56.   menuPtr   : MenuPtr;
  57.  
  58.  
  59.  
  60.  
  61. BEGIN
  62.  
  63.  
  64.   (* Open intuition library *)
  65.   IntuitionBase := OpenLibrary (IntuitionName,IntuitionRev);
  66.   IF IntuitionBase = 0 THEN
  67.     WriteString ("Open intuition failed"); WriteLn;
  68.   END;
  69.  
  70.   (* Create Heap to contain dynamic storage *)
  71.   HEAP := CreateHeap(15000);
  72.   IF ~HEAP THEN
  73.     WriteString('Heap was not created'); WriteLn;
  74.   END;
  75.  
  76.  IF (IntuitionBase # 0) & (HEAP) THEN
  77.  
  78.  
  79.   (* Initialize Gadgets *)
  80.   InitBorder (bPtr);
  81.   InitGadgets(gPtr, bPtr);
  82.  
  83.   (* Initialize the New window structure and open window *)
  84.   NEW( wp );
  85.   InitWindow ( wp, gPtr[0]);
  86.  
  87.   (* We draw bPtr[3] into window RastPort. 
  88.        This is the border for Calculator display         *)
  89.    DrawBorder( wp^.RPort^, bPtr[3]^, 8, 18 );
  90.  
  91.   (* Initialize Menu Strip *)
  92.    menuPtr := InitMenus();
  93.    SetMenuStrip( wp^ , menuPtr^ );
  94.  
  95.  
  96.   (* Initialize display *)
  97.    DisplayX( NoError, wp );
  98.  
  99.   (* Initialize the signal Mask *)
  100.   Sig1 := SignalSet {};
  101.   (* Convert signal number to a mask *)
  102.   INCL (Sig1, CARDINAL (wp^.UserPort^.mpSigBit));
  103.  
  104.   (* Wait for message *)
  105.   LOOP
  106.    (* Wait for the signal *)
  107.    Sig1 := Wait (Sig1);
  108.     Signal := GetMsg( wp^.UserPort );
  109.     IF Signal = NULL THEN
  110.       EXIT;
  111.      ELSE
  112.       IF Signal^.Class = IDCMPFlagSet{CloseWindowFlag} THEN
  113.          (* We have a close window request. Leave loop and close up *)
  114.          EXIT;
  115.        ELSIF Signal^.Class = IDCMPFlagSet{MenuPick} THEN
  116.         (* We have a menu selection. Handle it. *)
  117.          IF ~MenuHandle( Signal^.Code, wp ) THEN EXIT; END;
  118.         (* We might have a new display mode *)
  119.          DisplayX( NoError, wp );
  120.        ELSE
  121.          Button  := Signal^.IAddress;
  122.          CGadget := Button^.GadgetID;
  123.          IF (CGadget >= 0) & (CGadget < 10) THEN
  124.              EXTENDX( CGadget );
  125.              DisplayX( NoError, wp );
  126.           ELSIF CGadget <= 20 THEN
  127.              KEY  := Button^.UserData;
  128.              DisplayX( KEY^.CalcKey(), wp );
  129.           ELSE
  130.              SAME := FALSE;
  131.              DECI := FALSE;
  132.              NDeci:= 0;
  133.              KEY  := Button^.UserData;
  134.              DisplayX( KEY^.CalcKey(), wp );
  135.          END;
  136.       END;
  137.     END;
  138.   END;
  139.  
  140.   (* Close the window *)
  141.   ClearMenuStrip(wp^);
  142.   CloseWindow (wp^);
  143.  
  144.   (* Clean up *)
  145.   CloseLibrary(IntuitionBase);
  146.   DestroyHeap;
  147.  
  148.  END 
  149. END Calculator.
  150.